package 反射;


import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.regex.Pattern;

public class ShowMethods {
	private static String usage = "usage:\n";
	private static Pattern pattern = Pattern.compile("\\w+\\.");

	void sayHello(Integer i) {
	}

	public static void main(String[] args) throws ClassNotFoundException {


		showMethodUse(new String[]{"反射.ShowMethods"});
	}

	private static void showMethodUse(String[] args) throws ClassNotFoundException {
		if (args.length < 1) {
			System.out.println(usage);
			System.exit(1);
		}
		int lines = 0;
		Class<?> c = Class.forName(args[0]);
		Method[] methods = c.getMethods();
		Constructor<?>[] cors = c.getConstructors();
		if (args.length == 1) {
			for (Method method : methods) {
				System.out.println(pattern.matcher(method.toString()).replaceAll(""));
			}
			for (Constructor<?> cor : cors) {
				System.out.println(pattern.matcher(cor.toString()).replaceAll(""));
			}
			lines = methods.length + cors.length;
		} else {
			for (Method method : methods) {
				if (method.toString().indexOf(args[1]) != -1) {
					System.out.println(pattern.matcher(method.toString()).replaceAll(""));
					lines++;
				}
			}
			for (Constructor<?> cor : cors) {
				if (cor.toString().indexOf(args[1]) != -1) {
					System.out.println(pattern.matcher(cor.toString()).replaceAll(""));
					lines++;
				}
			}
		}
	}
}
